<template>
  <div class="user-add-main">
    <el-form ref="addForm" :model="addjobs" clearable filterable label-width="90px">
      <el-form-item label="岗位:" prop="jobsId" :rules="addRules.jobsId">
        <el-select v-model="addjobs.jobsId" clearable placeholder="请选择岗位">
          <el-option
            v-for="item in typeList"
            :key="item.id"
            :label="item.jobsName"
            :value="item.id"/>
        </el-select>
      </el-form-item>
      <el-form-item label="维度名称:" prop="dimensionName" :rules="addRules.dimensionName">
        <el-input v-model="addjobs.dimensionName"  />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" size="mini" @click="onSubmit">确定</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import dimensionApi from '@/api/dimension'

export default {
  data() {
    return {
      addjobs:{
        jobsId: "",
        dimensionName: ""
      },
      typeList:{},
      addRules: {
        jobsId: [{ type: 'String', required: true, trigger: 'blur', validator: (rule, value, callback) => {
                if (value=="") {
                  callback(new Error('*岗位不能为空!'))
                } else {
                  this.$refs['addForm'].clearValidate(['jobsId']);
                  callback()
                }
              }
        }],
        dimensionName: [{ type: 'String', required: true, trigger: 'blur', validator: (rule, value, callback) => {
                if (value=="") {
                  callback(new Error('*维度名称不能为空!'))
                } else {
                  this.$refs['addForm'].clearValidate(['dimensionName']);
                  callback()
                }
              }
        }],
      }
    }
  },
  created(){
    this.typeList = this.$store.getters.typeList
  },
  methods: {
    onSubmit() {
        this.$refs.addForm.validate(valid => {
        if (valid) {
          dimensionApi.add(this.addjobs).then(res => {
            this.$message.success(res.data)
            this.$emit('closeDisplay')
            this.$emit('getPageList')
            this.$refs.addForm.resetFields()
          })
        } else {
          return false
        }
      })
    }
  }
}
</script>

<style>
  .user-add-main{
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
  }
</style>
